package com.examination.exam.service.impl;

import com.examination.auth.utils.JacksonUtil;
import com.examination.domain.exam.entity.Examination;
import com.examination.exam.mapper.ExaminationMapper;
import com.examination.exam.service.ExaminationService;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExaminationServiceImpl implements ExaminationService {

    @Autowired
    private ExaminationMapper examinationMapper;


    @Override
    public Examination getExaminationById(Object id) {
        return examinationMapper.queryById(id);
    }

    @Override
    public void addExamination(Examination examination) {
        examinationMapper.insert(examination);
    }

    @Override
    public List<Examination> getExaminationByQuery(Bson query) {
        return examinationMapper.query(query);
    }

    @Override
    public long updateExamination(Bson filter, Bson bson) {
        return examinationMapper.updateMany(filter, bson).getModifiedCount();
    }

    @Override
    public long replaceExamination(Bson filter, Examination examination) {
        Document document = Document.parse(JacksonUtil.toJsonString(examination));
        return examinationMapper.replaceOne(filter, document).getModifiedCount();
    }

    @Override
    public boolean removeById(Long id) {
        return false;
    }
}
